package com.luoye.lj.util.converter;

/**
 * Created with IntelliJ IDEA.
 * User: Dave Liu
 * Date: 15-10-16
 * Time: 上午10:34
 * To change this template use File | Settings | File Templates.
 */
public class LabelConverter {
    //从位置列表字符串到Label的转换
    public static int fromListToLabel(String idList){
        int label=0;
        if(idList!=null){
            String ids[]=idList.split(",");
            for(String idstr:ids){
                int id=-1;
                try {
                    id= Integer.parseInt(idstr);
                }catch (NumberFormatException ex){
                    System.out.println(ex.getMessage());
                }
                if(id>-1){
                    label=label|(1<<id);
                }
            }
        }
        return label;
    }

    //从Label转换到位置列表字符串的转换
    public static String fromLabelToList(int label){
        StringBuilder sb=new StringBuilder("");
        for (int i=0;i<32;i++){
            if((label&(1<<i))>0){
               sb.append(",");
               sb.append(i);
            }
        }
        return sb.toString();
    }
}
